package craft.service;


import java.util.Iterator;
import java.util.List;
/*
import org.hibernate.Session;
import org.hibernate.Transaction;
*/
import common.AbstractService;

//import craft.entity.CraftType;

public class CraftManagerService extends AbstractService
{
	/*public CraftType createCraft(CraftType pCraftType , CraftScenarioType pCraftScenarioType , ContextType pContextType)
	{
		CraftType result = null;
		if( pCraftType!= null)
		{
			/*Session session = getSession();
			Transaction tx = session.beginTransaction();
			session.save(pCraftType);
			tx.commit();
			session.refresh(pCraftType);
			session.close();
			result = pCraftType;
		}
		return result;
	}
	public void deleteCraft(CraftKeyType pCraftKeyType , CraftScenarioType pCraftScenarioType , ContextType pContextType)
	{
		if( pCraftKeyType != null)
		{
			Session session = getSession();
			CraftKeyType result =  (CraftKeyType) session.get(CraftKeyType.class, pCraftKeyType.getId());
			if( result != null)
			{
				Transaction tx = session.beginTransaction();
				session.delete(result);
				tx.commit();
			}
			session.close();
		}
	}
	public CraftListType findCraft(CraftCriteriaType pCraftCriteriaType , CraftScenarioType pCraftScenarioType , ContextType pContextType)
	{
		CraftListType result = null;
		if( pCraftCriteriaType != null)
		{
			result = new CraftListType();
			Session session = getSession();
			Criteria crit = session.createCriteria(CraftCriteriaType.class);
			crit.setMaxResults(10);
			List<CraftType> resultCrit = crit.list();
			Iterator<CraftType> it = resultCrit.iterator();
			while(it.hasNext())
			{
				result.getValues().add(it.next());
			}
		}
		return result;
	}
	public CraftType getCraft(CraftKeyType pCraftKeyType , CraftScenarioType pCraftScenarioType , ContextType pContextType)
	{
		CraftType result = null;
		if( pCraftKeyType != null)
		{
			Session session = getSession();
			result =  (CraftType) session.get(CraftType.class, pCraftKeyType.getId());
			session.close();
		}
		return result;
	}
	public CraftType postCraft(CraftType pCraftType , CraftScenarioType pCraftScenarioType , ContextType pContextType)
	{
		CraftType result = null;
		if( pCraftType != null)
		{
			Session session = getSession();
			Transaction tx = session.beginTransaction();
			session.saveOrUpdate(pCraftType);
			tx.commit();
			session.close();
			session.refresh(pCraftType);
			result = pCraftType;
		}
		return result;
	}*/
}
